package com.example.shop.service.impl;

import com.example.shop.mapper.ShopCartMapper;
import com.example.shop.model.Role;
import com.example.shop.model.ShopCart;
import com.example.shop.service.ShopCartService;
import com.example.shop.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShopCartServiceImpl implements ShopCartService {
    @Autowired
    private ShopCartMapper shopCartMapper;

    @Override
    public List<ShopCart> getShopCarts(int uId) {
        return shopCartMapper.getShopCarts(uId);
    }

    @Override
    public int insertShopCart(ShopCart shopCart) {
        return shopCartMapper.insertShopCart(shopCart);
    }

    @Override
    public int updateShopCart(ShopCart shopCart) {
        return shopCartMapper.updateShopCart(shopCart);
    }

    @Override
    public int deleteShopCart(int id) {
        return shopCartMapper.deleteByPrimaryKey(id);
    }

    @Override
    public ShopCart getShopCart(int commodityId, int uId) {
        return shopCartMapper.getShopCart(commodityId, uId);
    }

    @Override
    public PageBean<ShopCart> getShopCart(int pageNo, int pageSize, String search) {
        PageBean<ShopCart> pageBean = new PageBean<>();
        pageBean.setPageSize(pageSize);
        pageBean.setDataCount(shopCartMapper.getDataCount());
        pageBean.setPageNo(pageNo);
        if ("".equals(search) || search.length() == 0) {
            search = null;
        }
        pageBean.setDataList(shopCartMapper.getShopCartPage((pageNo - 1) * pageSize, pageSize, search));
        return pageBean;
    }
}
